package com.orange.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.orange.dbhelp.page.Page;
import com.orange.handler.AuthSchoolContactService;
import com.orange.modules.bean.SessionUser;
import com.orange.modules.entity.school.AuthSchoolContacts;
import com.orange.util.ReturnCode;

@Controller
@RequestMapping("/schoolContacts")
public class AuthContactsController extends BaseController{

	private static final Logger log = Logger.getLogger(AuthSchoolContactsController.class);

	@Autowired
	private AuthSchoolContactService authSchoolContactService;
	
	/**
	 * 分页显示联系人
	 */
	@RequestMapping(value="/queryContacts" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryContacts(HttpServletRequest request,HttpServletResponse response,@RequestBody Map<String,String> map){
		
		try {		
			String pid=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
			if(null==pid){
				return toResponse(null,ReturnCode.NOLOGIN,"未登录");
			}
			String pageSize = map.get("pageSize");
			String pageNumber = map.get("pageNumber");
			if(StringUtils.isBlank(pageSize)||StringUtils.isBlank(pageNumber)){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "参数存在空值");
			}
			AuthSchoolContacts ac = authSchoolContactService.queryAuthSchoolContactsBySchoolId(pid);
			if(null == ac){
				return toResponse(null, ReturnCode.PARAMETER_NOT_NULL, "了无音讯");
			}
			//map.put("type", ac.getType());
			Page<AuthSchoolContacts> page = authSchoolContactService.queryAuthContactsBytype(Integer.valueOf(pageNumber), Integer.valueOf(pageSize), map);
			return toResponse(page,ReturnCode.SUCCESS,"查询机构联系人信息成功");
		} catch (Exception e) {
			log.info("查询机构联系人信息失败",e);
			return toResponse(null, ReturnCode.FAIL, "查询机构联系人信息失败");
		}
	}




}
